CONTENTS | INDEX | PREV | NEXT
dir
NAME
dir - directory scanning routines
SYNOPSIS
#include <sys/dir.h>
DIR *dirhan = opendir(path);
struct direct *entry = readdir(dirhan);
(void) rewinddir(dirhan);
void closedir(dirhan);
const char *path;
DIR *dirhan;
FUNCTION
These are UNIX compatible directory scanning calls. After openning
a directory with opendir(), you may scan it with successive
calls to readdir() until NULL is returned, then either
rewinddir() it for a rescan, or closedir() it when done.
The DIR structure is private to the library. Valid fields within
struct direct are d_name (the file name), and d_namlen (the length
of the file name, not usually needed).
You can chdir() into the directory and stat() each entry to obtain
additional information. Note that the UNIX directory scanning
routines will not be as efficient as the Amiga directory scanning
routines, but are portable.
NOTE
Unlike the amiga directory scanning routines that use Lock()s,
these calls will automatically deallocate resources if the program
terminates.
rewinddir()'s prototype returns an int .. this is for internal
use only, you should never use rewinddir()'s return value
yourself.
EXAMPLE
#include <stdio.h>
#include <sys/dir.h>
main(ac, av)
int ac;
char *av[];
{
DIR *dir;
if (ac == 1) {
puts("test dir");
exit(1);
}
if (dir = opendir(av[1])) {
struct direct *entry;
while (entry = readdir(dir)) {
printf("%sn", entry->d_name);
}
closedir(dir);
}
return(0);
}
SEE ALSO
chdir